<%--
  Created by IntelliJ IDEA.
  User: wangh
  Date: 2020/12/21
  Time: 15:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>管理员登录</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-3.3.1.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <script>
        function refreshCode() {
            let elementById = document.getElementById("vcode");
            elementById.src = "${pageContext.request.contextPath}/checkCodeServlet?time=" + new Date().getTime();
        }

        function checkForm() {
            var nametip = checkUserName();
            var passtip = checkPassword();
            return nametip && passtip;
        }

        function checkUserName() {
            var username = document.getElementById('username');
            var errname = document.getElementById('nameErr');
            if (username.value.length == 0) {
                errname.innerHTML = "用户名不能为空"
                errname.className = "error"
                return false;
            } else {
                errname.innerHTML = "OK"
                errname.className = "success";
                return true;
            }
        }

        function checkPassword() {
            var userpasswd = document.getElementById('password');
            var errPasswd = document.getElementById('passwordErr');
            if (userpasswd.value.length == 0) {
                errPasswd.innerHTML = "密码不能为空"
                errPasswd.className = "error"
                return false;
            } else {
                errPasswd.innerHTML = "OK"
                errPasswd.className = "success";
                return true;
            }
        }
    </script>
</head>
<body style="background-color: #F2F2F2">
<%
    request.setCharacterEncoding("utf-8");
    HttpSession session1 = request.getSession();
    session1.setAttribute("login_requestURI",request.getRequestURI());
%>
<div class="logoBar"
     style="height: 75px;background: #1d7ad9;font-size: 35px;font-weight: bolder;padding-left: 100px;padding-top: 12px;color: white;">
    电脑销售管理后台
</div>
<div class="container" style="width: 400px;background-color: #ffffff;margin-top: 20px;border-radius: 10px">
    <h3 style="text-align: center;">管理员登录</h3>
    <form action="${pageContext.request.contextPath}/loginServlet" method="post" onSubmit="return checkForm()">
        <div class="form-group">
            <label for="username">用户名：</label>
            <input type="text" name="username" class="form-control" id="username" placeholder="请输入用户名"
                   onBlur="checkUserName()" oninput="checkUserName()"/>
            <span id="nameErr"></span>
        </div>

        <div class="form-group">
            <label for="password">密码：</label>
            <input type="password" name="password" class="form-control" id="password" placeholder="请输入密码"
                   onBlur="checkUserName()" oninput="checkPassword()"/>
            <span id="passwordErr"></span>
        </div>

        <div class="form-inline">
            <label for="vcode">验证码：</label>
            <input type="text" name="verifycode" class="form-control" id="verifycode" placeholder="请输入验证码"
                   style="width: 120px;"/>
            <a href="javascript:refreshCode()">
                <img src="${pageContext.request.contextPath}/checkCodeServlet" title="看不清点击刷新" id="vcode"/>
            </a>
        </div>
        <hr/>
        <div class="form-group" style="text-align: center;">
            <input class="btn btn btn-primary" type="submit" value="登录" style="width: 100%;">
        </div>
    </form>
    <div style="font-size: medium;width: 100%;margin-bottom: 10px;text-align: right;">
        <a href="${pageContext.request.contextPath}/register.jsp">管理员注册</a>
    </div>
    <!-- 出错显示的信息框 -->
    <div class="alert alert-warning alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
        <strong>提示信息:</strong>${message}
    </div>
</div>
</body>
</html>